package com.rephilo.proxy.handler;

import com.rephilo.proxy.ProxyTransaction;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * JDK代理处理流程
 *
 * @author rephilo
 */
public class JDKProxyHandler implements InvocationHandler {

    private Object realObject;

    private ProxyTransaction proxyTransaction = new ProxyTransaction();

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //此处可使用职责链模式改造，解析每一个注解
        return proxyTransaction.doMethodInvokeWithTransaction(realObject, method, args);
    }

    public JDKProxyHandler(Object realObject) {
        this.realObject = realObject;
    }
}
